<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        body {
            margin: 0;
            /*padding: 50px 0 0 120px;*/
        }

        div {
            border: 1px solid red;
        }

        #outer {
            width: 300px;
            height: 200px;
            position: relative;
            top: 50px;
            left: 120px;
            text-align: center;
            font-size: 30px;
            /*padding-top: 100px;*/
        }

        #inner {
            width: 200px;
            height: 50px;
            display: inline-block;
            position: relative;
            top: 50%;
        }

        span {
            background-color:yellow;
            color: #fff;
        }
    </style>
</head>
<body>
    
    <div id="outer">
        <div id="inner">
             111111111111111111111111111111
            <span id="span">my span</span>
        </div>
    </div>

    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <script>
        // !function() {
            var span = document.getElementById('span');
            var outer = document.getElementById('outer');
            var inner = document.getElementById('inner');

            var off = getOffset(span);
            console.log(off);

            /**
             * 参数：dom 对象
             * 返回值：{top: 10px, left: 20px}
             */
            function getOffset(domElement) {
                var top, left;
                var parent = domElement.offsetParent;
                left = domElement.offsetLeft;
                top = domElement.offsetTop;

                while (parent) {
                    left += parent.offsetLeft;
                    top += parent.offsetTop;
                    parent = parent.offsetParent;
                }

                return {"top": top, "left": left};

            }
        // }();
    </script>

</body>
</html>